package com.escool.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.escool.model.TbNivel;
@Repository
public class NivelesDAOImpl implements NivelesDAO {
	
	@Autowired
	SessionFactory sessionFactory;

	@Override
	public void addNiveles(TbNivel nivel) {
		this.sessionFactory.getCurrentSession().save(nivel);

	}

	@Override
	public void updateNiveles(TbNivel nivel) {
		this.sessionFactory.getCurrentSession().update(nivel);

	}

	@Override
	public List<TbNivel> listNiveles() {
		
		return this.sessionFactory.getCurrentSession().createQuery("from TbNivel").list();
	}

	@Override
	public TbNivel findNiveles(Integer id) {
		
		return (TbNivel) this.sessionFactory.getCurrentSession().get(TbNivel.class, id);
	}

	@Override
	public void deleteNiveles(Integer id) {
		TbNivel nivel = (TbNivel) this.sessionFactory.getCurrentSession().load(TbNivel.class, id);
		if(nivel != null){
			this.sessionFactory.getCurrentSession().delete(nivel);
		}

	}

}
